package cc.rengu.redp.bizimpl.upmp.controller;

import cc.rengu.igas.bomp.facade.BompThirdMchntEntryService;
import cc.rengu.redp.bizimpl.enums.PayChannelEnum;
import cc.rengu.redp.bizimpl.igas.domain.PDstChannelCfg;
import cc.rengu.redp.bizimpl.igas.service.PDstChannelCfgService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpBMchntBaseInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.service.WechatRiskService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.upmp.vo.WechatRiskVO;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 无交易终端及二维码管理的控制类
 * 
 * @author yuhongwen
 * @date 2020年4月13日 下午16:33:10
 */

@Api("微信风险商户违规查询")
@RestController
@RequestMapping(value = "/admin/merParam/wechatRisk")
public class WechatRiskController extends BaseController {


    @Autowired
    private WechatRiskService wechatRiskService;

    @Autowired
    private PDstChannelCfgService pDstChannelCfgService;

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

//    @Autowired
//    private BompThirdMchntEntryService bompThirdMchntEntryService;
//    @Autowired
//    private MchntApplyInfoService mchntApplyInfoService;
//    @Autowired(required = false)
//    private BompThirdMchntEntryService bompThirdMchntEntryService;
//    @Autowired
//    private CbcParamsService cbcParamsService;
    @Autowired
    private IUpmpBMchntBaseInfoService bMchntBaseInfoService;



    @Log("分页")
//    @RequiresPermissions("风险管理:微信风险商户违规查询")
    @GetMapping( "/list")
    public Map<String, Object> findByPage(QueryRequest request, WechatRiskVO wechatRiskVO )throws RedpException {
        return getDataTable(wechatRiskService.findFromBomp(request,wechatRiskVO,bMchntBaseInfoService.genMerOrder(wechatRiskVO.getInstId())));
    }


    @Log("微信通道类型")
    @GetMapping("/findPDstChannelCfgList")
    public Map<String, Object>findPDstChannelCfgList(QueryRequest request, String q)throws RedpException {
//        String q = request.getParameter("q");
//        if (null == q) {
//            return null;
//        }
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        String param1=null;
        q=q.replaceAll("&amp;", "&");
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            param1=param[0];
        }
//        Page page;
//        String defaultRows = request.getParameter(BusinessContainer.ECP_DEFAULTROWS_PARA_NAME);
//        if(Common.isBlank(defaultRows))defaultRows = BusinessContainer.ECP_PAGE_MAXROWS;
//        Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request,Integer.parseInt(defaultRows));

        List<PDstChannelCfg> pDstChannelCfgList = pDstChannelCfgService.findPDstChannelCfgList(user.getInstId(), PayChannelEnum.WXZF.getType(),"");
        Map<String, Object> maps = new HashMap<String, Object>();
        Map<String, String> map = new HashMap<String, String>();
        List<Object> list = new ArrayList<Object>();
        for (int i = 0; i < pDstChannelCfgList.size(); i++) {
            map = new HashMap<String, String>();
            map.put("id", pDstChannelCfgList.get(i).getDstChannelType());
            map.put("name", pDstChannelCfgList.get(i).getDstChannelTypeDesc());
            list.add(map);
        }
        maps.put("results", list);
        maps.put("more", false);
        return maps;

    }

}

